/**
 @file ctc_asw_interrupt.h

 @author  Copyright (C) 2012 Centec Networks Inc.  All rights reserved.

 @date 2020-06-24

 @version v2.0

 This module is an asynchronous mechanism which allow hardware/chip to communicate with the software.
 For example, when learning cache in chip exceed threshold, chip notify software though interrupt;
 software received this interrupt, read out the entries in learning cache and notify application to add these MAC entries.
 User need to determine four things below.
 \p
 \d your application needs how many interrupt groups/PINs [0,5], and the IRQs and task priority of each group.
 \d your application needs register how many events (ctc_interrupt_event_t), and the callback function of registered events
 \d initialize interrupt module by parameter or by change group & interrupt default configuration in sys_usw_interrupt_isr.c
 \b

\S ctc_interrupt.h:ctc_interrupt_event_t
\S ctc_interrupt.h:ctc_intr_group_t
\S ctc_interrupt.h:ctc_intr_global_cfg_t
*/

#ifndef _CTC_ASW_INTERRUPT_H
#define _CTC_ASW_INTERRUPT_H
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
*
* Header Files
*
***************************************************************/
#include "ctc_interrupt.h"
/****************************************************************
*
* Defines and Macros
*
****************************************************************/
enum ctc_asw_interrupt_cb_e
{
    CTC_ASW_CB_L2_SW_LEARNING = 0,
    CTC_ASW_CB_L2_STATION_MOVE,
    CTC_ASW_CB_PCS_LINK,
    CTC_ASW_CB_ECC_ERROR,
    CTC_ASW_CB_DMA,
    CTC_ASW_CB_MAX
};
typedef enum ctc_asw_interrupt_cb_e ctc_asw_interrupt_cb_t;

struct ctc_asw_intr_info_s
{
    CTC_INTERRUPT_FUNC  isr[CTC_ASW_CB_MAX];
    CTC_INTERRUPT_EVENT_FUNC event_isr[CTC_EVENT_MAX];
    sal_task_t* p_polling_task;
    ctc_intr_group_t intr_group[CTC_INTR_MAX_GROUP];
};
typedef struct ctc_asw_intr_info_s ctc_asw_intr_info_t;

/****************************************************************
*
* Function
*
***************************************************************/

/**
 @addtogroup interrupt INTERRUPT
 @{
*/
/**
 @brief Initialize interrupt module

 @param[in] lchip    local chip id

 @param[in] p_global_cfg    pointer to interrupt initialize parameter, refer to ctc_intr_global_cfg_t

 @remark[TMA]  User can initialize the interrupt configuration though p_global_cfg parameter,  If the p_global_cfg is NULL,
         SDK will using default configuration.

 @return CTC_E_XXX
*/
extern int32
ctc_asw_interrupt_init(uint8 lchip, void* p_global_cfg);

/**
 @brief De-Initialize interrupt module

 @param[in] lchip    local chip id

 @remark[TMA]  User can de-initialize the interrupt configuration

 @return CTC_E_XXX
*/
extern int32
ctc_asw_interrupt_deinit(uint8 lchip);

/**
 @brief Register event callback function

 @param[in] lchip    local chip id

 @param[in]  event      Event type

 @param[in]  cb         Callback function to handle this event type

 @remark[TMA]  User register callback functions of application concerned events though this API

 @return CTC_E_XXX
*/
extern int32
ctc_asw_interrupt_register_event_cb(uint8 lchip, ctc_interrupt_event_t event, CTC_INTERRUPT_EVENT_FUNC cb);

/**@} end of @addtogroup interrupt INTERRUPT */

INTERNAL extern int32
_ctc_asw_intr_get_event_func(uint8 lchip, ctc_interrupt_event_t intr_cb, CTC_INTERRUPT_EVENT_FUNC* isr);

INTERNAL extern int32
_ctc_asw_intr_register_cb_func(uint8 lchip, ctc_asw_interrupt_cb_t intr_cb, CTC_INTERRUPT_FUNC isr);

#ifdef __cplusplus
}
#endif

#endif

